package com.ali.sofa;

import com.ali.sofa.domain.Dog;
import com.ali.sofa.domain.Person;
import com.ali.sofa.domain.Pig;
import com.ali.sofa.domain.Sheep;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Optional;

@SpringBootApplication
/**
 * 1、开启属性配置功能
 * 2、把类放到IOC容器中
 */
@EnableConfigurationProperties({Sheep.class, Person.class})
public class MainApplication {
    public static void main(String[] args) {
        //var只能用在局部变量
        var ioc = SpringApplication.run(MainApplication.class, args);

        var beanDefinitionNames = ioc.getBeanDefinitionNames();
        ArrayList<String> li = new ArrayList<>();
        Collections.addAll(li,beanDefinitionNames);
        li.forEach((str)->{

            if (str.contains("dog")){
                System.out.println(str+"存在dog");
            }

            if (str.contains("cat")){
                System.out.println(str+"存在cat");
            }

        });



        Pig pig = ioc.getBean("pig", Pig.class);
        System.out.println(pig);

        var sheep = ioc.getBean(Sheep.class);

        System.out.println(sheep);

        var person = ioc.getBean(Person.class);

        System.out.println(person);

    }
}